package com.example.neusoft215gdh.androidpro_21.Activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.neusoft215gdh.androidpro_21.Common.utilMeth;
import com.example.neusoft215gdh.androidpro_21.JavaBean.BannerView;
import com.example.neusoft215gdh.androidpro_21.JavaBean.ClubCourse;
import com.example.neusoft215gdh.androidpro_21.JavaBean.ClubDetail;
import com.example.neusoft215gdh.androidpro_21.JavaBean.ClubList;
import com.example.neusoft215gdh.androidpro_21.Listener.ClubListener;
import com.example.neusoft215gdh.androidpro_21.Model.ClubModel;
import com.example.neusoft215gdh.androidpro_21.R;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import static com.example.neusoft215gdh.androidpro_21.R.drawable.b;

/**
 * Created by hp-pc on 2017/10/16.
 */
public class ClubCourseActivity extends AppCompatActivity implements ClubListener,utilMeth,View.OnClickListener {

    private int[] imgs = {R.drawable.a, b,R.drawable.c,R.drawable.d};
    private List<View> viewList;
    BannerView bannerView;
    Button club_intro;
    ImageView reg;
    String clubid;
    ImageView imageView;
    TextView name;
    TextView hit;
    String userid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.club_class);
        viewList = new ArrayList<View>();
        for (int i = 0; i < imgs.length; i++) {
            ImageView image = new ImageView(this);
            image.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            //设置显示格式
            image.setScaleType(ImageView.ScaleType.CENTER_CROP);
            image.setImageResource(imgs[i]);
            viewList.add(image);
        }
        bannerView = (BannerView) findViewById(R.id.bannerCourse);
        bannerView.startLoop(true);
        bannerView.setViewList(viewList);
        initViews();
        Intent intent=getIntent();
        clubid=intent.getStringExtra("clubid");
        initViews();
        ClubModel clubModel=new ClubModel();
        SharedPreferences user=getSharedPreferences("Userid",0);
        userid=user.getString("user_id","");
        clubModel.getClubDetail(userid,clubid,"1","Clubcourse",this);
        reg.setOnClickListener(this);//调用监听
        club_intro.setOnClickListener(this);
    }

    @Override
    public void initViews() {
       imageView= (ImageView) findViewById(R.id.class_pic);
        name= (TextView) findViewById(R.id.club_clubname);
        hit= (TextView) findViewById(R.id.hits);
        reg= (ImageView) findViewById(R.id.reg_returnCourse1);
        club_intro= (Button) findViewById(R.id.club_intro);
    }
    @Override
    public void onResponse(List<ClubList> bean) {
    }
    @Override
    public void onResponseClubDetailVideo(List<ClubDetail> bean) {
    }

    @Override
    public void onResponseClubDetailjianjie(ClubDetail bean) {
    }

    @Override
    public void onResponseClubDetailCourse(ClubCourse bean) {
        if(!bean.getThumb().isEmpty())
        {
            Picasso.with(this).load("http://172.24.10.175/workout/Uploads/"+bean.getThumb()).into(imageView);
        }
        else
        {
            imageView.setImageResource(R.drawable.ic_person);
        }
        name.setText(bean.getClub_name());
        hit.setText(bean.getHits());
    }
    @Override
    public void onFail(String msg) {
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.reg_returnCourse1:
                finish();
                break;
            case R.id. club_intro:
                finish();
                break;
        }
    }
}
